using LiJ.Framework.Msg.Mos;

namespace LiJ.Framework.Msg
{
	/// <inheritdoc />
	/// <summary>
	/// 消息处理类
	///  </summary>
	public class WxMsgHandler : WxMsgBaseHandler
	{
		private WxMsgProcessor<WxTextRecMsg> textPro;

		private WxMsgProcessor<WxImageRecMsg> imagePro;

		private WxMsgProcessor<WxVoiceRecMsg> voicePro;

		private WxMsgProcessor<WxVideoRecMsg> videoPro;

		private WxMsgProcessor<WxVideoRecMsg> shortVideoPro;

		private WxMsgProcessor<WxLocationRecMsg> locationPro;

		private WxMsgProcessor<WxLinkRecMsg> linkPro;

		private WxMsgProcessor<WxSubScanRecEventMsg> subEventPro;

		private WxMsgProcessor<WxSubScanRecEventMsg> unsubEventPro;

		private WxMsgProcessor<WxSubScanRecEventMsg> scanEventPro;

		private WxMsgProcessor<WxLocationRecEventMsg> locationEventPro;

		private WxMsgProcessor<WxClickRecEventMsg> clickEventPro;

		private WxMsgProcessor<WxViewRecEventMsg> viewEventPro;

		/// <summary>
		/// 构造函数
		/// </summary>
		public WxMsgHandler()
			: this(null)
		{
		}

		/// <summary>
		/// 构造函数
		/// </summary>
		/// <param name="mConfig"></param>
		public WxMsgHandler(WxMsgConfig mConfig)
			: base(mConfig)
		{
		}

		/// <summary>
		/// 处理文本消息
		/// </summary>
		protected virtual WxBaseReplyMsg ProcessTextMsg(WxTextRecMsg msg)
		{
			return null;
		}

		/// <summary>
		/// 处理图像消息
		/// </summary>
		protected virtual WxBaseReplyMsg ProcessImageMsg(WxImageRecMsg msg)
		{
			return null;
		}

		/// <summary>
		/// 处理语音消息
		/// </summary>
		protected virtual WxBaseReplyMsg ProcessVoiceMsg(WxVoiceRecMsg msg)
		{
			return null;
		}

		/// <summary>
		/// 处理视频消息
		/// </summary>
		protected virtual WxBaseReplyMsg ProcessVideoMsg(WxVideoRecMsg msg)
		{
			return null;
		}

		/// <summary>
		/// 处理小视频消息
		/// </summary>
		protected virtual WxBaseReplyMsg ProcessShortVideoMsg(WxVideoRecMsg msg)
		{
			return null;
		}

		/// <summary>
		/// 处理地理位置消息
		/// </summary>
		protected virtual WxBaseReplyMsg ProcessLocationMsg(WxLocationRecMsg msg)
		{
			return null;
		}

		/// <summary>
		/// 处理链接消息
		/// </summary>
		protected virtual WxBaseReplyMsg ProcessLinkMsg(WxLinkRecMsg msg)
		{
			return null;
		}

		/// <summary>
		/// 处理关注事件
		/// </summary>
		protected virtual WxBaseReplyMsg ProcessSubscribeEventMsg(WxSubScanRecEventMsg msg)
		{
			return null;
		}

		/// <summary>
		/// 处理取消关注事件
		/// </summary>
		protected virtual WxNoneReplyMsg ProcessUnsubscribeEventMsg(WxSubScanRecEventMsg msg)
		{
			return null;
		}

		/// <summary>
		/// 处理扫描带参数二维码事件
		/// </summary>
		protected virtual WxBaseReplyMsg ProcessScanEventMsg(WxSubScanRecEventMsg msg)
		{
			return null;
		}

		/// <summary>
		/// 处理上报地理位置事件
		/// 不需要回复任何消息
		/// </summary>
		protected virtual WxNoneReplyMsg ProcessLocationEventMsg(WxLocationRecEventMsg msg)
		{
			return null;
		}

		/// <summary>
		/// 处理点击菜单拉取消息时的事件推送
		/// </summary>
		protected virtual WxBaseReplyMsg ProcessClickEventMsg(WxClickRecEventMsg msg)
		{
			return null;
		}

		/// <summary>
		/// 处理点击菜单跳转链接时的事件推送 
		/// </summary>
		protected virtual WxBaseReplyMsg ProcessViewEventMsg(WxViewRecEventMsg msg)
		{
			return null;
		}

		internal override WxMsgProcessor GetBasicMsgProcessor(string msgType, string eventName)
		{
			switch (msgType.ToLower())
			{
			case "event":
				return this.GetBasicEventMsgProcessor(eventName);
			case "text":
			{
				object wxMsgProcessor5 = this.textPro;
				if (wxMsgProcessor5 == null)
				{
					WxMsgProcessor<WxTextRecMsg> obj3 = new WxMsgProcessor<WxTextRecMsg>
					{
						RecInsCreater = (() => new WxTextRecMsg()),
						ProcessFunc = this.ProcessTextMsg
					};
					WxMsgProcessor<WxTextRecMsg> wxMsgProcessor6 = obj3;
					this.textPro = obj3;
					wxMsgProcessor5 = wxMsgProcessor6;
				}
				return (WxMsgProcessor)wxMsgProcessor5;
			}
			case "image":
			{
				object wxMsgProcessor9 = this.imagePro;
				if (wxMsgProcessor9 == null)
				{
					WxMsgProcessor<WxImageRecMsg> obj5 = new WxMsgProcessor<WxImageRecMsg>
					{
						RecInsCreater = (() => new WxImageRecMsg()),
						ProcessFunc = this.ProcessImageMsg
					};
					WxMsgProcessor<WxImageRecMsg> wxMsgProcessor10 = obj5;
					this.imagePro = obj5;
					wxMsgProcessor9 = wxMsgProcessor10;
				}
				return (WxMsgProcessor)wxMsgProcessor9;
			}
			case "voice":
			{
				object wxMsgProcessor3 = this.voicePro;
				if (wxMsgProcessor3 == null)
				{
					WxMsgProcessor<WxVoiceRecMsg> obj2 = new WxMsgProcessor<WxVoiceRecMsg>
					{
						RecInsCreater = (() => new WxVoiceRecMsg()),
						ProcessFunc = this.ProcessVoiceMsg
					};
					WxMsgProcessor<WxVoiceRecMsg> wxMsgProcessor4 = obj2;
					this.voicePro = obj2;
					wxMsgProcessor3 = wxMsgProcessor4;
				}
				return (WxMsgProcessor)wxMsgProcessor3;
			}
			case "video":
			{
				object wxMsgProcessor13 = this.videoPro;
				if (wxMsgProcessor13 == null)
				{
					WxMsgProcessor<WxVideoRecMsg> obj7 = new WxMsgProcessor<WxVideoRecMsg>
					{
						RecInsCreater = (() => new WxVideoRecMsg()),
						ProcessFunc = this.ProcessVideoMsg
					};
					WxMsgProcessor<WxVideoRecMsg> wxMsgProcessor8 = obj7;
					this.videoPro = obj7;
					wxMsgProcessor13 = wxMsgProcessor8;
				}
				return (WxMsgProcessor)wxMsgProcessor13;
			}
			case "shortvideo":
			{
				object wxMsgProcessor7 = this.shortVideoPro;
				if (wxMsgProcessor7 == null)
				{
					WxMsgProcessor<WxVideoRecMsg> obj4 = new WxMsgProcessor<WxVideoRecMsg>
					{
						RecInsCreater = (() => new WxVideoRecMsg()),
						ProcessFunc = this.ProcessShortVideoMsg
					};
					WxMsgProcessor<WxVideoRecMsg> wxMsgProcessor8 = obj4;
					this.shortVideoPro = obj4;
					wxMsgProcessor7 = wxMsgProcessor8;
				}
				return (WxMsgProcessor)wxMsgProcessor7;
			}
			case "location":
			{
				object wxMsgProcessor11 = this.locationPro;
				if (wxMsgProcessor11 == null)
				{
					WxMsgProcessor<WxLocationRecMsg> obj6 = new WxMsgProcessor<WxLocationRecMsg>
					{
						RecInsCreater = (() => new WxLocationRecMsg()),
						ProcessFunc = this.ProcessLocationMsg
					};
					WxMsgProcessor<WxLocationRecMsg> wxMsgProcessor12 = obj6;
					this.locationPro = obj6;
					wxMsgProcessor11 = wxMsgProcessor12;
				}
				return (WxMsgProcessor)wxMsgProcessor11;
			}
			case "link":
			{
				object wxMsgProcessor = this.linkPro;
				if (wxMsgProcessor == null)
				{
					WxMsgProcessor<WxLinkRecMsg> obj = new WxMsgProcessor<WxLinkRecMsg>
					{
						RecInsCreater = (() => new WxLinkRecMsg()),
						ProcessFunc = this.ProcessLinkMsg
					};
					WxMsgProcessor<WxLinkRecMsg> wxMsgProcessor2 = obj;
					this.linkPro = obj;
					wxMsgProcessor = wxMsgProcessor2;
				}
				return (WxMsgProcessor)wxMsgProcessor;
			}
			default:
				return null;
			}
		}

		private WxMsgProcessor GetBasicEventMsgProcessor(string eventName)
		{
			switch (eventName.ToLower())
			{
			case "subscribe":
			{
				object wxMsgProcessor7 = this.subEventPro;
				if (wxMsgProcessor7 == null)
				{
					WxMsgProcessor<WxSubScanRecEventMsg> obj4 = new WxMsgProcessor<WxSubScanRecEventMsg>
					{
						RecInsCreater = (() => new WxSubScanRecEventMsg()),
						ProcessFunc = this.ProcessSubscribeEventMsg
					};
					WxMsgProcessor<WxSubScanRecEventMsg> wxMsgProcessor4 = obj4;
					this.subEventPro = obj4;
					wxMsgProcessor7 = wxMsgProcessor4;
				}
				return (WxMsgProcessor)wxMsgProcessor7;
			}
			case "unsubscribe":
			{
				object wxMsgProcessor3 = this.unsubEventPro;
				if (wxMsgProcessor3 == null)
				{
					WxMsgProcessor<WxSubScanRecEventMsg> obj2 = new WxMsgProcessor<WxSubScanRecEventMsg>
					{
						RecInsCreater = (() => new WxSubScanRecEventMsg()),
						ProcessFunc = this.ProcessUnsubscribeEventMsg
					};
					WxMsgProcessor<WxSubScanRecEventMsg> wxMsgProcessor4 = obj2;
					this.unsubEventPro = obj2;
					wxMsgProcessor3 = wxMsgProcessor4;
				}
				return (WxMsgProcessor)wxMsgProcessor3;
			}
			case "scan":
			{
				object wxMsgProcessor8 = this.scanEventPro;
				if (wxMsgProcessor8 == null)
				{
					WxMsgProcessor<WxSubScanRecEventMsg> obj5 = new WxMsgProcessor<WxSubScanRecEventMsg>
					{
						RecInsCreater = (() => new WxSubScanRecEventMsg()),
						ProcessFunc = this.ProcessScanEventMsg
					};
					WxMsgProcessor<WxSubScanRecEventMsg> wxMsgProcessor4 = obj5;
					this.scanEventPro = obj5;
					wxMsgProcessor8 = wxMsgProcessor4;
				}
				return (WxMsgProcessor)wxMsgProcessor8;
			}
			case "location":
			{
				object wxMsgProcessor5 = this.locationEventPro;
				if (wxMsgProcessor5 == null)
				{
					WxMsgProcessor<WxLocationRecEventMsg> obj3 = new WxMsgProcessor<WxLocationRecEventMsg>
					{
						RecInsCreater = (() => new WxLocationRecEventMsg()),
						ProcessFunc = this.ProcessLocationEventMsg
					};
					WxMsgProcessor<WxLocationRecEventMsg> wxMsgProcessor6 = obj3;
					this.locationEventPro = obj3;
					wxMsgProcessor5 = wxMsgProcessor6;
				}
				return (WxMsgProcessor)wxMsgProcessor5;
			}
			case "click":
			{
				object wxMsgProcessor9 = this.clickEventPro;
				if (wxMsgProcessor9 == null)
				{
					WxMsgProcessor<WxClickRecEventMsg> obj6 = new WxMsgProcessor<WxClickRecEventMsg>
					{
						RecInsCreater = (() => new WxClickRecEventMsg()),
						ProcessFunc = this.ProcessClickEventMsg
					};
					WxMsgProcessor<WxClickRecEventMsg> wxMsgProcessor10 = obj6;
					this.clickEventPro = obj6;
					wxMsgProcessor9 = wxMsgProcessor10;
				}
				return (WxMsgProcessor)wxMsgProcessor9;
			}
			case "view":
			{
				object wxMsgProcessor = this.viewEventPro;
				if (wxMsgProcessor == null)
				{
					WxMsgProcessor<WxViewRecEventMsg> obj = new WxMsgProcessor<WxViewRecEventMsg>
					{
						RecInsCreater = (() => new WxViewRecEventMsg()),
						ProcessFunc = this.ProcessViewEventMsg
					};
					WxMsgProcessor<WxViewRecEventMsg> wxMsgProcessor2 = obj;
					this.viewEventPro = obj;
					wxMsgProcessor = wxMsgProcessor2;
				}
				return (WxMsgProcessor)wxMsgProcessor;
			}
			default:
				return null;
			}
		}
	}
}
